package com.cilico.single.view;

import java.util.ArrayList;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.cilico.single.components.Component;
import com.cilico.single.components.CssStyle;
import com.cilico.single.components.Panel;
import com.cilico.single.utils.Utils;

/**
 * Form节点线形管理器控件�?
 * 该控件只因为客户端和服务段来�?��据中对form节点有联动属性控制才产生. 
 * form节点类的�?��控件都加载到该管理器,然后盖管理器在加载到界面管理器llv_
 * @author lv.xiangan
 *
 */
public class FormLayout extends LinearLayout implements Panel {

	protected CssStyle cssStyle_;
	private ArrayList<Component> children_;

	String[] relaEnable_;
	String[] relaDisable_;
	String[] relaVisible_;
	String[] relaInvisible_;
	private BaseView bv_;
	private int height_;
	public String attrName_;

	public FormLayout(Context context) {
		super(context);
		bv_ = (BaseView) context;
		// TODO Auto-generated constructor stub
		// 设置该控件得对其方式为垂�?
		this.setOrientation(LinearLayout.VERTICAL);
		// set margin.
		LinearLayout.LayoutParams lop = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		setLayoutParams(lop);
		setGravity(Gravity.CENTER_HORIZONTAL);
	}

	public void addView(View child) {
		try {
			Component c = (Component) child;
			c.mould();
			BaseView.setComponentTopMargin(c);
			super.addView(c.getCmpView());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
	}

	public void cleanText() {
		// TODO Auto-generated method stub

	}

	public String getContentText() {
		// TODO Auto-generated method stub
		return null;
	}

	public void mould() {
		// TODO Auto-generated method stub

	}

	public void setContentText(String text) {
		// TODO Auto-generated method stub

	}

	public void shrinkWidth() {
		// TODO Auto-generated method stub

	}

	public void setCmpHeidht(int height) {
		// TODO Auto-generated method stub

	}

	public void setCmpWidth(int width) {
		// TODO Auto-generated method stub

	}

	public void setCssStyle(CssStyle style) {
		cssStyle_ = style;
	}

	public View getCmpView() {
		return this;
	}

	public void addChild(Component cmp) {
		if (children_ == null) {
			children_ = new ArrayList<Component>();
		}
		children_.add(cmp);
	}

	public void loadAllChildren() {
		if (children_ == null) {
			return;
		}
		BaseView.appendChildIntoLayout(bv_, this, children_, 0);
	}

	public int childrenAmount() {
		if (children_ != null) {
			return children_.size();
		}
		return 0;
	}

	public Component child(int index) {
		try {
			return children_.get(index);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			Utils.printException(e);
		}
		return null;
	}

	public void removeChild(Component cmp) {
		// TODO Auto-generated method stub

	}

	public int getCmpHeight() {
		return height_;
	}

	public int getCmpWidth() {
		// TODO Auto-generated method stub
		return 0;
	}

	public void setInTable(boolean inTable) {
		// TODO Auto-generated method stub

	}

	public boolean isInTable() {
		// TODO Auto-generated method stub
		return false;
	}

	public CssStyle getCssStyle() {
		// TODO Auto-generated method stub
		return null;
	}

	public void releaseResource(View view) {
		// TODO Auto-generated method stub
		// cssStyle_ = null;
		// children_ = null;
		// relaEnable_ = null;
		// relaDisable_ = null;
		// relaVisible_ = null;
		// relaInvisible_ = null;
		Utils.releaseResource(view);
	}

	public void setForm(FormLayout formLayout) {
		// TODO Auto-generated method stub

	}

	public FormLayout getForm() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void setEncrypt(String encrypt) {
		// TODO Auto-generated method stub
	}

}
